xend: Unlink VDI instances and VBD instances
authorKeir Fraser <keir.fraser@citrix.com>
Fri, 25 Sep 2009 09:46:13 +0000 (10:46 +0100)
committerKeir Fraser <keir.fraser@citrix.com>
Fri, 25 Sep 2009 09:46:13 +0000 (10:46 +0100)
VBD information in xend does not have a VDI value if XenAPI mode
is invalid. A new patch confirms the VDI value is valid.  So, the new
patch cuts off VDI->VBD links if the VDI value is valid.

Signed-off-by: Masaki Kanno <kanno.masaki@jp.fujitsu.com>
tools/python/xen/xend/XendDomain.py
tools/python/xen/xend/XendDomainInfo.py

index 594d49298a61289901ba1a9dfd0912b5559b1601..7a125fb23ae8c9eadca3994ce406596daed7d347 100644 (file)
@@ -347,6 +347,7 @@ class XendDomain:
             if self.is_domain_managed(dom):
                 self._managed_config_remove(dom.get_uuid())
                 del self.managed_domains[dom.get_uuid()]
+                dom.unlink_xapi_instances()
                 dom.destroy_xapi_instances()
         except ValueError:
             log.warn("Domain is not registered: %s" % dom.get_uuid())
@@ -485,6 +486,7 @@ class XendDomain:
             if domid in self.domains:
                 del self.domains[domid]
 
+            info.unlink_xapi_instances()
             info.destroy_xapi_instances()
         else:
             log.warning("Attempted to remove non-existent domain.")
index 124c910768c54104230ca88295c6b9e5de271540..b7a4307ebbbdbc6b0f34f0655de703207496e819 100644 (file)
@@ -4043,6 +4043,20 @@ class XendDomainInfo:
             except Exception, exn:
                 raise XendError('Failed to destroy device')
 
+    def unlink_xapi_instances(self):
+        from xen.xend import XendDomain
+        if XendDomain.instance().is_valid_vm(self.info.get('uuid')):
+            # domain still exists.
+            return
+
+        for vbd_ref in self.info.get('vbd_refs'):
+            dev_info = self.info['devices'].get(vbd_ref)[1]
+            vdi_uuid = dev_info.get('VDI', None)
+            if vdi_uuid and XendNode.instance().is_valid_vdi(vdi_uuid):
+                vdi = XendNode.instance().get_vdi_by_uuid(vdi_uuid)
+                if vdi.getVBDs().count(vbd_ref):
+                    vdi.removeVBD(vbd_ref)
+
     def destroy_xapi_instances(self):
         """Destroy Xen-API instances stored in XendAPIStore.
         """